package fr.azzale.casu.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import fr.azzale.casu.activity.TribuneActivity;
import fr.azzale.casu.metier.Line;
import fr.azzale.casu.metier.Tribune;
import fr.azzale.casu.views.LineView;

public class TribuneListAdapter extends BaseAdapter {

	private Tribune tribune;
	private TribuneActivity activity;

	public TribuneListAdapter(TribuneActivity tribuneActivity, Tribune result) {
		this.tribune = result;
		this.activity = tribuneActivity;
	}

	@Override
	public int getCount() {
		if(tribune==null || tribune.getEntries() == null)
			return 0;
		return tribune.getEntries().size();
	}

	@Override
	public Object getItem(int position) {
		return tribune.getEntries().get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null)
		{
			convertView = new LineView(activity);
		}
		LineView v = (LineView)convertView;
		v.display((Line)getItem(position));
		return v;
	}

	public void clear() {
		this.tribune.getEntries().clear();
	}


}
